from ..utils.utils import *
from ..myModels.categoryModel import *
import json

from drf_yasg.utils import swagger_auto_schema
from drf_yasg import openapi
from rest_framework.decorators import api_view
from rest_framework.response import Response

@api_view(['get'])
def category_all(request):
    values = Category.objects.all().values()
    return success(list(values))

@api_view(['get'])
def category_add(request):
    return info('添加分类')


def category_add_json(request):
    with open('fresh/data/category.json', encoding='utf-8') as json_file:
        data = json.load(json_file)

    for item in data:
        Category.objects.get_or_create(
            name=item['name'], iconUrl=item['iconUrl'])
    return info(data)
